<template>
  <div class="login-container dis">
    <div class="normal-left" />
    <div style="flex: 1;">
      <el-form
        ref="loginForm"
        :model="loginForm"
        :rules="loginRules"
        class="login-form"
        autocomplete="on"
        label-position="left"
      >

        <div class="title-container">
          <h3 class="title">欢迎登录</h3>
        </div>
        <div class="foSi14 mar-bott5">用户名/手机号</div>
        <el-form-item prop="username" class="mar-bott30">
          <el-input
            ref="username"
            v-model="loginForm.username"
            placeholder="请填写用户名/手机号"
            name="username"
            type="text"
            tabindex="1"
            autocomplete="on"
          />
        </el-form-item>
        <div class="foSi14 mar-bott5">密码</div>
        <el-form-item prop="password" class="mar-bott30">
          <el-input
            ref="password"
            v-model="loginForm.password"
            type="password"
            placeholder="请填写密码"
            name="password"
            tabindex="2"
            autocomplete="on"
            @keyup.enter.native="handleLogin"
          />
        </el-form-item>

        <el-button
          :loading="loading"
          type="primary"
          class="borRad40"
          style="width:100%;margin-bottom:30px;background: #6b7cdd;border: 0;"
          @click.native.prevent="handleLogin"
        >登录</el-button>
        <div class="dis disAl foSi14">
          <el-checkbox v-model="loginForm.zidong">
            <span>30天自动登录</span>
          </el-checkbox>
          <span class="forget-password cuPo" @click.stop="tuanzhuan('/retakePassword')">忘记密码</span>
          <!-- <div class="mar-left30">还没有账号？<span class="cuPo" style="color: #6b7cdd;"
							@click.stop="tuanzhuan('/register')">注册</span></div> -->
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import {
  validTel
} from '@/utils/validate'
import { dbiglogin } from '@/api/user'
import { AddEdit } from '@/api/staff'
import Cookies from 'js-cookie'
export default {
  name: 'Login',
  components: {},
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请填写正确手机号'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error('请填写正确密码'))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        username: '',
        password: '',
        zidong: true
      },
      loginRules: {
        username: [{
          required: true,
          trigger: 'blur',
          validator: validateUsername
        }],
        password: [{
          required: true,
          trigger: 'blur',
          validator: validatePassword
        }]
      },
      loading: false,
      redirect: undefined
    }
  },
  created(options) {
    console.log(options)
  },
  methods: {
    tuanzhuan(url) {
      this.$router.push({
        path: url
      })
    },
    handleLogin() {
      // 登录成功后请求点大后台登录
      this.loginnew()
    },
    loginnew() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('user/login', this.loginForm).then(res => {
            localStorage.setItem('loginuser', JSON.stringify(this.loginForm))
            this.$router.push({
              path: '/switchVenue'
            })
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss">
	/* 修复input 背景不协调 和光标变色 */
	/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

	$bg: #283443;
	$light_gray: #fff;
	$cursor: #fff;

	@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
		.login-container .el-input input {
			// color: $cursor;
		}
	}

	/* reset element-ui css */
	.login-container {
		.el-input {
			display: inline-block;
			height: 40px;

			input {
				background: transparent;
				border: 0px;
				-webkit-appearance: none;
				border-radius: 0px;
				padding: 12px 5px 12px 15px;
				// color: $light_gray;
				height: 40px;
				// caret-color: $cursor;

				&:-webkit-autofill {
					box-shadow: 0 0 0px 1000px $bg inset !important;
					// -webkit-text-fill-color: $cursor !important;
				}
			}
		}

		.el-form-item {
			// border: 1px solid rgba(255, 255, 255, 0.1);
			border: 1px solid #f2f2f2;
			// background: rgba(0, 0, 0, 0.1);
			border-radius: 5px;
			color: #000;
		}
	}
</style>

<style lang="scss" scoped>
	$bg: #2d3a4b;
	$dark_gray: #889aa4;
	$light_gray: #eee;

	.login-container {
		height: 100%;
		width: 100%;
		// background-color: $bg;
		overflow: hidden;

		.normal-left {
			width: 640px;
			height: 100%;
			background: url('../../icons/png/aac4b1ee0969d44a27cec7e39e3ca61.jpg') no-repeat left top;
			background-size: cover;
		}

		.login-form {
			position: relative;
			width: 520px;
			max-width: 100%;
			padding: 160px 35px 0;
			margin: 0 auto;
			overflow: hidden;
		}

		.tips {
			font-size: 14px;
			// color: #fff;
			margin-bottom: 10px;

			span {
				&:first-of-type {
					margin-right: 16px;
				}
			}
		}

		.svg-container {
			padding: 6px 5px 6px 15px;
			// color: $dark_gray;
			vertical-align: middle;
			width: 30px;
			display: inline-block;
		}

		.title-container {
			position: relative;

			.title {
				font-size: 26px;
				// color: $light_gray;
				margin: 0px auto 40px auto;
				// text-align: center;
				font-weight: bold;
			}

			.set-language {
				// color: #fff;
				position: absolute;
				top: 3px;
				font-size: 18px;
				right: 0px;
				cursor: pointer;
			}
		}

		.show-pwd {
			position: absolute;
			right: 10px;
			top: 7px;
			font-size: 16px;
			// color: $dark_gray;
			cursor: pointer;
			user-select: none;
		}

		.thirdparty-button {
			position: absolute;
			right: 0;
			bottom: 6px;
		}

		@media only screen and (max-width: 470px) {
			.thirdparty-button {
				display: none;
			}
		}

		.custom-checkbox {
			width: 16px;
			height: 16px;
			margin-right: 8px;
		}

		.forget-password {
			margin-left: auto;
			color: #bbb;
		}
	}
</style>
